package com.cn.jinl.controller;

import com.cn.jinl.api.IOnDutyBgService;
import com.cn.jinl.api.ISalaryService;
import com.cn.jinl.domain.OnDutyBg;
import com.cn.jinl.domain.Salary;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ResponseBody
    @RequestMapping("/getSalaryList/{frontToken}")
    public JsonResponse<List<Salary>> getSalaryList(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<Salary>> response = new JsonResponse<List<Salary>>();
        List<Salary> result = salaryService.getSalaryList(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/addOrUpdateSalary/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addOrUpdateSalary(@RequestBody Salary salary, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = salaryService.addOrUpdateSalary(salary);
        return CommonUtil.getResponseData(response,result);
    }
}
